
// admin模块的业务逻辑
const Admin = require('../dao/model/Admin')
const {where} = require("sequelize");

exports.addAdmin = async function(adminObj) {
    const ins = await Admin.create(adminObj)
    console.log(ins.name + '管理员创建成功')
    return ins.toJSON()
}

exports.delAdmin = async function(adminId) {
    // 1.方式一
    // const ins = await Admin.findByPk(adminId)
    // await ins.destroy()
    // 2.方式二
    await Admin.destroy({where: {id:adminId}})
    console.log('删除成功')
}

exports.updateAdmin = async function(adminId,adminObj) {
    // 1.方式一
    // const ins = await Admin.findByPk(adminId)
    // ins.name = adminObj.name
    // await ins.save()
    // 2.方式二
    await Admin.update(adminObj , {where: {id: adminId}})
    console.log('修改成功')
}